package com.dk.controller;

import com.dk.bean.Result;
import com.dk.em.ResultEnum;
import com.dk.feign.CarManagementFeign;
import com.dk.pojo.CarMessage;
import com.dk.service.CarMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("message")
@Api(description = "车辆信息查询")
public class CarMessageController {

    @Autowired
    private CarMessageService carMessageService;

    @GetMapping
    @ApiOperation(value = "车辆信息查询")
    private Result toSelect(){
        return Result.buildResult(ResultEnum.SUCCESS).setData(carMessageService.toSelect());
    }

    @PostMapping
    @ApiOperation(value = "车辆信息的增加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CarMessage", value = "车辆信息实体类", required = true, paramType = "body"),
    })
    public Result toInsert(@RequestBody CarMessage carMessage){
        return Result.buildResult(ResultEnum.SUCCESS).setData(carMessageService.toInsert(carMessage) + "增加成功");
    }

    @GetMapping(value = "/{messageId}")
    @ApiOperation(value = "根据id车辆信息查询回显")
    private Result toSelectById(@PathVariable("messageId") Long messageId){
        return Result.buildResult(ResultEnum.SUCCESS).setData(carMessageService.toSelectById(messageId));
    }

    @PutMapping
    @ApiOperation(value = "车辆信息的修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CarMessage", value = "车辆信息实体类", required = true, paramType = "body")
    })
    private Result update(@RequestBody CarMessage carMessage){
        return Result.buildResult(ResultEnum.SUCCESS).setData(carMessageService.toUpdate(carMessage) + "修改成功");
    }
}
